-- buff显示组件
-- local BillBoard = require("gameLogic.ui.BillBoard")
local BuffDisplayComponent = class("BuffDisplayComponent")
local Vector3 = require("utils.Vector3")
local StrategyHelper = require("gameLogic.fightSkill.strategy.StrategyHelper")
local StrategyConst = require("gameLogic.fightSkill.strategy.StrategyConst")
local BuffComposite = require("gameLogic.buff.buffBase.BuffComposite")

function BuffDisplayComponent:ctor(manager, entity, whoEntity, config)
    self._manager = manager
    self._buffComposite = BuffComposite.new(entity, whoEntity, config)
end

function BuffDisplayComponent:awake()
    self.transform.localScale = Vector3.new(1, 1, 1)
    self._imageIcon = self.gameObject:GetComponentInChildren(typeof(Unity.UI.Image))
    local obj = G_ResourceManager:loadSprite("BuffAtlas", self._buffComposite:getConfig().icon)
    self._imageIcon.sprite = obj
end

function BuffDisplayComponent:getType()
    return self._buffComposite:getType()
end

function BuffDisplayComponent:remove()
    if self._manager then
        self._manager:removeBuff(self)
    end
end

function BuffDisplayComponent:addChild(buff)
    self._buffComposite:addChild(buff)
    self:_updateCount()
end

function BuffDisplayComponent:removeChild(buff)
    self._buffComposite:removeChild(buff)
end

function BuffDisplayComponent:check()
    self._buffComposite:check()
    self:_updateCount()
    if self._buffComposite:getChildCount() == 0 then
        self:remove()
    end
end

function BuffDisplayComponent:_updateCount()
    local count = self._buffComposite:getChildCount()
    -- if count <= 1 then
    --     self._textCount.text = ""
    -- else
    --     self._textCount.text = count
    -- end
end

function BuffDisplayComponent:onDestroy()
    self._buffComposite:onDestroy()
end

return BuffDisplayComponent
